package xin.nick.persistence.core.entity;

import xin.nick.persistence.core.manager.TransactionalManager;

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Nick
 * @date 2021/5/5
 * @description 核心配置类,数据源,MappedStatementMap 等..
 */
public class Configuration {

    /**
     * 数据源
     */
    private DataSource dataSource;

    /**
     * 映射配置类的映射
     */
    Map<String, MappedStatement> mappedStatementMap = new HashMap<>();

    /**
     * 事务管理器
     */
    TransactionalManager transactionalManager = new TransactionalManager();

    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        transactionalManager.setDataSource(dataSource);
        this.dataSource = dataSource;
    }

    public TransactionalManager getTransactionalManager() {
        return transactionalManager;
    }

    public void setTransactionalManager(TransactionalManager transactionalManager) {
        this.transactionalManager = transactionalManager;
    }

    public Map<String, MappedStatement> getMappedStatementMap() {
        return mappedStatementMap;
    }

    public void setMappedStatementMap(Map<String, MappedStatement> mappedStatementMap) {
        this.mappedStatementMap = mappedStatementMap;
    }

    public Connection getConnection() {
        return transactionalManager.getCurrentThreadConn();
    }
}
